package com.example.jisuanji5;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

public class transition extends AppCompatActivity {


    EditText editText;
    TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_transition);

        textView = findViewById(R.id.transition_result);
        editText = findViewById(R.id.transition_input);

        RadioGroup radioGroup = findViewById(R.id.radioGroup);
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                RadioButton radioButton = findViewById(i);
                String s = radioButton.getText().toString();
                textView.setText("您点击了"+s);
                Button transition = findViewById(R.id.transition);
                transition.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        String str = editText.getText().toString();
                        int input = Integer.parseInt(str);
                        if (s.equals("二进制")){
                            textView.setText(Integer.toBinaryString(input)); }
                        else if (s.equals("八进制")){
                            textView.setText(Integer.toOctalString(input)); }
                        else
                            textView.setText(Integer.toHexString(input));

                    }
                });
            }
        });

        Button transition_back = findViewById(R.id.transition_back);
        transition_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(transition.this,MainActivity.class);
                startActivity(intent);
            }
        });


    }
}